#ifndef __WXD_SINGLETON_H__
#define __WXD_SINGLETON_H__

#include "defs.h"
#include "component.h"

template<typename T>
class WXDLLIMPEXP_DIRECTUI wxDSingleton : public wxDComponent
{
private:
	wxDSingleton(const wxDSingleton<T> &);

	wxDSingleton& operator=(const wxDSingleton<T> &);
	
protected:
	static T* msSingleton;

public:
	wxDSingleton(const wxString& id, bool managed = true)
		: wxDComponent(id, managed)
	{
		wxASSERT( !msSingleton );
		msSingleton = static_cast<T*>(this);
	}

	virtual ~wxDSingleton()
	{
		wxASSERT( msSingleton );
		msSingleton = 0;
	}

	static T& GetSingleton()
	{
		wxASSERT( msSingleton );
		return *msSingleton;
	}

	static T* GetSingletonPtr()
	{
		wxASSERT( msSingleton );
		return msSingleton;
	}
};

#endif